<template>
    <div>
        <c-header :p-title="'全部会议'">
            <btn-refresh class='m-l-15' :p-data='init'></btn-refresh>
        </c-header>
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <div class="table-responsive"  v-if='list'>
                            <table class="vm table color-bordered-table base-bordered-table table-bordered table-hover">
                                <thead>
                                <tr class="nowrap">
                                    <!--<th>ID</th>-->
                                    <th>主题</th>
                                    <th>开始时间</th>
                                    <th>结束时间</th>
                                    <th width="60">操作</th>
                                </tr>
                                </thead>
                                <tbody  v-show='list.length'>
                                <tr v-for="(item,key) in list">
                                    <!--<td>{{item.id}}</td>-->
                                    <td>{{item.title}}</td>
                                    <td>{{item.start_at}}</td>
                                    <td>{{item.end_at}}</td>
                                    <td class="no-h-bg">
                                        <div class="table-edit-group">
                                            <Tooltip content="查看" placement="top">
                                                <button class="btn btn-sm btn-info"  @click='lookAtDetail("see",{id:item.id})'><i class="fa fa-eye"></i></button>
                                            </Tooltip>
                                            <Tooltip content="编辑" placement="top">
                                                <button v-if="edit_group.qxgly_edit_bt==1" class="btn btn-sm btn-success m-l-sm"  @click='lookAtDetail("edit",{id:item.id})'><i class="fa fa-edit"></i></button>
                                            </Tooltip>
                                            <button v-if="edit_group.qxgly_manager_worker_bt==1" class="btn btn-sm btn-dark m-l-sm"  @click='lookAtDetail("worker")'>管理管理员</button>
                                            <button v-if="edit_group.qxgly_access_bt==1" class="btn btn-sm btn-primary m-l-sm"  @click='lookAtDetail("role")'>权限设置</button>
                                            <button v-if='edit_group.qxgly_hdgl_bt==1' class="btn btn-sm btn-dark m-l-sm"  @click='lookAtDetail("child_conference",item)'>分活动管理</button>
                                            <button v-if='edit_group.qxgly_delall_bt==1' class="btn btn-sm btn-dark m-l-sm"  @click='lookAtDetail("clean_data",item)'>清除数据</button>
                                            <!--客商信息管理员-->
                                            <button v-if="edit_group.zhygly_lrysh_bt==1" class="btn btn-sm btn-info m-l-sm"  @click='lookAtDetail("write_worker")'>管理客商信息录入员</button>
                                            <button v-if="edit_group.zhygly_chrysh_bt==1" class="btn btn-sm btn-primary m-l-sm"  @click='lookAtDetail("verity_customer")'>审核参会人员</button>
                                            <button v-if="edit_group.zhygly_qbchry_bt==1" class="btn btn-sm btn-dark m-l-sm"  @click='lookAtDetail("all_customer")'>全部参会人员</button>
                                            <button v-if="edit_group.zhygly_backup_bt==1" class="btn btn-sm btn-dark m-l-sm"  @click='lookAtDetail("data_copy")'>数据备份</button>
                                            <button v-if="edit_group.zhygly_file_bt==1"  class="btn btn-sm btn-info m-l-sm"  @click='lookAtDetail("files_manage")'>文件管理</button>
                                            <!--TODO 客商信息录入员-->
                                            <button v-if='edit_group.lry_people_submit_bt==1' class="btn btn-sm btn-dark m-l-sm"  @click='lookAtDetail("apply_customer")'>客商信息录入</button>
                                            <!--TODO 分活动管理员-->
                                            <button v-if='edit_group.fhygly_hdgl_bt==1' class="btn btn-sm btn-dark m-l-sm"  @click='lookAtDetail("child_with_conference",item)'>分活动管理</button>
                                            <!--TODO 陪同管理员-->
                                            <button v-if='edit_group.ptgly_people_bt==1' class="btn btn-sm btn-dark m-l-sm"  @click='lookAtDetail("with_customer",item)'>陪同参会人员管理</button>
                                            <button v-if='edit_group.ptgly_ptry_bt==1' class="btn btn-sm btn-dark m-l-sm"  @click='lookAtDetail("with_worker",item)'>陪同人员管理</button>
                                            <!--TODO 陪同人员-->
                                            <button v-if='edit_group.ptry_people_bt==1' class="btn btn-sm btn-dark m-l-sm"  @click='lookAtDetail("with_sub",item)'>查看陪同信息</button>
                                            <!--TODO 客商信息浏览-->
                                            <button v-if='edit_group.leader_people_bt==1' class="btn btn-sm btn-dark m-l-sm"  @click='lookAtDetail("leader_customer",item)'>全部参会人员</button>
                                            <!--TODO 酒店管理员-->
                                            <button v-if='edit_group.jd_people_bt==1' class="btn btn-sm btn-dark m-l-sm"  @click='lookAtDetail("hotel_worker",item)'>全部参会人员</button>

                                        </div>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                            <div  v-show='!list.length' class="text-center m-b-sm">
                                暂无数据！
                            </div>
                        </div>
                        <hr/>
                        <!--<footer class="panel-footer text-right">
                            <CPage :total="search.page_total"
                                   :current='search.page_current'
                                   :page-size='search.page_row'
                                   @on-change='pageCurrentChange'
                                   @on-page-size-change='pageRowChange'></CPage>
                        </footer>-->
                    </div>
                </div>
            </div>
        </div>
        <operate-detail ref="operate_detail"></operate-detail>
        <operate-save ref="operate_save" @on-change="initSubmit"></operate-save>
        <operate-clean ref="operate_clean" @on-change="initSubmit"></operate-clean>
    </div>
</template>
<script>
    import {mapGetters} from 'vuex'
    import serConference from '../../serves/api-conference'
    import OperateDetail from './detail'
    import OperateSave from './save'
    import OperateClean from './OperateClean'
    const __page_key = 'conference.list';
    let searchDef = {

        page_row:'',
        page_current:'',
        page_total:''
    };
    export default{
        components:{
            OperateDetail,
            OperateSave,
            OperateClean
        },
        data(){
            return{
                list:undefined,
                edit_group:{},
                search:{}
            }
        },
        computed:{
            ...mapGetters({
                "userData":"user"
            }),
        },
        beforeMount(){
            this.searchReset();
            this.conferenceChildLink();
        },
        mounted(){
            this.init();
        },
        methods:{
            searchReset(update,pageState){
                if(pageState){
                    this.$clientPage.def(this.search);
                    return false
                }
                const _p=this.$clientPage.getData(__page_key);
                if(_p){
                    this.$set(this,'search',_p);
                }else{
                    this.$set(this,'search',Object.assign({},searchDef));
                    this.$clientPage.def(this.search);
                }
                if(update){
                    this.init();
                }
            },
            searchPage(page){
                this.$clientPage.set(this.search,page);
            },
            searchChange(){
                this.$clientPage.def(this.search);
                this.init();
            },
            pageRowChange(num){
                if(num!= this.search.page_row){
                    this.$set(this.search,'page_row',num);
                    if(this.search.page_current == 1){
                        this.init();
                    }
                }
            },
            pageCurrentChange(current){
                if(current!= this.search.page_current){
                    this.$set(this.search,'page_current',current);
                    this.init();
                }
            },
            linkPageChange(name,params,query){
                this.$clientPage.setData(__page_key,Object.assign({},this.search));
                if(name){
                    this.$router.push({name:name,params:params,query:query})
                }
            },
            //------------------------------------------------------------------------
            async init(){
                let res = await serConference.list();
                if(res.code==1){
                    this.list = res.data||[];
                    this.edit_group = res.addtion_data&&res.addtion_data.button||{};
                    //this.searchPage(res.addtion_data&&res.addtion_data.page_info);
                }else{
                    this.list = [];
                    //this.searchReset(undefined,true);
                    this.$Message.error(res.message);
                }
                return true;
            },
            lookAtDetail(type,data){
                switch (type){
                    case "see":this.seeDetail(data);break;
                    case "edit":this.saveDetail(data);break;
                    case "worker":this.linkPageChange('workerPersonList');break;
                    case "role":this.linkPageChange('conferencePower');break;
                    case "write_worker":this.linkPageChange('workerWrite');break;
                    case "verity_customer":this.linkPageChange('customerVerityList');break;
                    case "all_customer": this.linkPageChange('customerList');break;
                    case "apply_customer":this.linkPageChange('workerWriteVerityList');break;
                    case "child_conference":this.linkPageChange('conferenceChildList',{id:data.id},{title:data.title});break;
                    case "child_with_conference":this.linkPageChange('conferenceChildWithList',{id:data.id},{title:data.title});break;
                    case "with_customer":this.linkPageChange('customerWithList',{id:data.id});break;
                    case "with_worker":this.linkPageChange('workerWithList',{id:data.id});break;
                    case "with_sub":this.linkPageChange('customerWithSubList',{id:data.id});break;
                    case "leader_customer":this.linkPageChange('leaderCustomerList',{id:data.id});break;
                    case "data_copy":this.linkPageChange('DataBackUpList');break;
                    case "hotel_worker":this.linkPageChange('workerHotelList');break;
                    case "clean_data": this.cleanDataSubmit(data);break;
                    case "files_manage":this.linkPageChange('conferenceFilesList');break;
                }

            },
            cleanDataSubmit(data){
                this.$refs['operate_clean'].handleOpen({
                    id:data&&data.id
                });

            },
            seeDetail(data){
                this.$refs['operate_detail'].handleOpen({
                    id:data.id
                })
            },
            saveDetail(data){
                this.$refs['operate_save'].handleOpen({
                    id:data.id
                })
            },
            initSubmit(state){
                if(state){
                    this.init()
                }
            },
            conferenceChildLink(){
                if(this.userData.submee_num){
                    if(this.userData.submee_num==1){
                        this.linkPageChange('customerConferChildList',{id:this.userData.sub_mee_id},{title:this.userData.sub_mee_title,no_return:true})
                    }else if(this.userData.submee_num>1){
                        this.linkPageChange('conferenceChildWithList',{id:this.userData.main_mee_id},{title:this.userData.main_mee_title,no_return:true})
                    }
                }
            }
        }
    }
</script>